﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;

namespace DC.Views
{
    public partial class Form_NewPatient : Skin_DevExpress
    {
        public Form_NewPatient()
        {
            InitializeComponent();
        }
        public string patientID = string.Empty;
        public string lasttime = string.Empty;
        Utils.Database DB = Utils.Global.GlobalDB;
        private void skinButton1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            string sql = string.Format(@"insert into Patient( Patient_Name,Patient_Location,Patient_Identity,Patient_Phone,Patient_Birthday,Patient_Sex,Patient_Debt,Patient_Last)values(
                                                '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
                                              name.Text.Trim(),
                                              location.Text.Trim(),
                                              Identity.Text.Trim(),
                                              phone.Text.Trim(),
                                              dateTimePicker1.Value.ToString().Trim(),
                                              sex.Text.Trim(),
                                              '0',
                                              lasttime

                                              );
            if (name.Text == string.Empty || phone.Text == string.Empty || sex.Text == string.Empty)
            {
                MessageBox.Show("录入信息不完全");
            }
            else if (Utils.DataCheck.CheckIdentity(Identity.Text) || Identity.Text.Trim() == string.Empty)
                {
                    
                    try
                    {
                        DB.Execute(sql);
                    }
                    catch (Exception)
                    {
                        _ = MessageBox.Show("身份证输入有误", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    MessageBox.Show("保存病人成功！", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DialogResult r = MessageBox.Show("是否继续添加项目", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (r == DialogResult.Yes)
                    {
                        name.Text = "";
                        location.Text = "";
                        Identity.Text = "";
                        phone.Text = "";
                        sex.Text = "";
                    }
                    else
                    {
                        this.Close();
                    }
                }
            else
                {
                    MessageBox.Show("身份证输入不合法");
                }
            }
        } 
}
